package hypeerweb;

import proxyCommand.ObjectDB;

public class Fold extends NodeDelegate  {
	private static final long serialVersionUID = 1L;

	public Fold(Node node) {
		delegate = node;
	}
	
	public void add(Node node) {}
	
	public void remove(Node node) {
//		System.out.println(node.getParent());
		if(node.getParent().getConnections().getSurrogateFold() == null) {
//			System.out.println("This one");
			node.getParent().setInverseSurrogateFold(node.getFold());
			node.getFold().setNewSurrogateFold(node.getParent());
			node.getFold().setFold(null);
		}
		else {
//			System.out.println("That one");
			node.getFold().setFold(node.getFold().getConnections().getInverseSurrogateFold());
			node.getParent().setFold(node.getFold());
			node.getParent().setNewSurrogateFold(null);
			node.getFold().setInverseSurrogateFold(null);
		}
//		ObjectDB.getSingleton().dump();
	}
	
	public void replace(Node node, Node replacingNode) {
		if(delegate != null) {
			delegate.replaceFold(replacingNode);
		}
	}
}
